package com.study.base.netty.nio;

import java.nio.IntBuffer;

/**
 * @description: BasicBuffer
 * @date: 2021/1/21 11:39
 * @author: hcm
 * @version: 1.0
 */
public class BasicBuffer {
    public static void main(String[] args) {
        //Buffer使用
        //创建一个buffer,大小为5，可以存放五个int
        IntBuffer intBuffer = IntBuffer.allocate(5);

        //向buffer存放数据
        for (int i = 0; i < intBuffer.capacity(); i++) {
            intBuffer.put(i*2);
        }
        //从buffer读取数据，buffer转换，读写切换
        intBuffer.flip();
        while (intBuffer.hasRemaining()){
            System.out.println(intBuffer.get());
        }
    }
}
